Skip to content

Fix update of the magnetic field#15632

Open
romainschotter wants to merge 1 commit into
AliceO2Group:devfrom
romainschotter:patch-2
Open

Fix update of the magnetic field#15632
romainschotter wants to merge 1 commit into
AliceO2Group:devfrom
romainschotter:patch-2

Conversation

@romainschotter

Copy link
Copy Markdown
Contributor

When using the standard CCDB loader, the magnetic field is initialised correctly.

However, when processing a second file from a different run, the TGeoGlobalMagField instance is deleted (

delete TGeoGlobalMagField::Instance();
), while the corresponding pointer mField is not reset (
mField = static_cast<o2::field::MagneticField*>(TGeoGlobalMagField::Instance()->GetField());
).

As a result, it becomes a dangling pointer and can return completely nonsensical magnetic field values (e.g. around 2e+22). The pointer therefore needs to be refreshed by calling updateField. Furthermore, updateField only updates the magnetic field if the pointer mField is a nullptr. If mField exists but points to invalid memory, updateField does not update the magnetic field, so this logic also had to be fixed.

Thank you @fchinu for reporting this bug!

@ddobrigk @dsekihat for your information!

@shahor02 shahor02 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romainschotter thanks, the fix is correct.
Could you hint at how you re-initialise it in the analysis for different runs?
In principle, if it is done via GRPGeomHelper, there no need to delete the field: the field GRP is a function if timestamp rather than the run number, one simply updates the current values.

@sawenzel
sawenzel marked this pull request as ready for review July 25, 2026 09:32
@sawenzel
sawenzel self-requested a review as a code owner July 25, 2026 09:32

@sawenzel sawenzel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me.

For full consistency, one should probably also do Instance()->mFieldFast = nullptr next to the mField reset in both overloads to remove the implicit dependency on updateField()'s internal branch condition for correctness of the fast-field cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants